﻿#include "langselector.h"
#include "../../_global.h"
#include "../containerscommon.h"

#ifdef _DEBUG
//#ifdef _CRTDBG_MAP_ALLOC
#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
//#endif 
#endif 

LangSelector::LangSelector():DataContainerBase(){

}

LangSelector::LangSelector(__int64 _ID):DataContainerBase(_ID){

}

LangSelector::~LangSelector(){
	
}

long LangSelector::parse(SPtr<FileContainer> _inFileContainer,long _offsetInData){

	long dataSize;
	char *dataBuf=NULL;

  if(preParse(_inFileContainer,_offsetInData,&dataBuf,&dataSize)!=1)return -1;
	if(dataBuf==NULL)return -5;

	//Разбор контейнера для конкретного типа (этого объекта):

	if(dataSize<8)return -4;
	setID(getFileContainer().p()->getID());

	memcpy((void *)(&ID_USTRING_SelectedLanguage),(void *)dataBuf,8);

	return 16;

}

long LangSelector::parse(){
	if(getFileContainer().isNULLPtr())return -1;
	if(getFileContainer().p()->getContainerType()!=CT_LANG_SELECTOR)return -3;
	return parse(getFileContainer(),0);
}

int LangSelector::join(){

	if(preJoin()!=1)return -1;
	if(checkAndSetObjectsAtIDs()<0)return -2;

	//сборка данных в контейнер:
	getFileContainer().p()->setContainerType(CT_LANG_SELECTOR);
	getFileContainer().p()->setID(getID());

	char* data;
	long size;
	
	size=8;
	data=new char[size];

	((__int64 *)data)[0]=ID_USTRING_SelectedLanguage;

	getFileContainer().p()->setDataCopy(data,size);
	delete [] data;
	return 0;

}

int LangSelector::checkAndSetObjectsAtIDs(){
  return 0;
}
